import pymysql
conn=None
cs=None
try:
    conn = pymysql.connect(host="211.103.136.244", port=7061,
                           user="student", password="iHRM_student_2021",
                           database="test_db", charset="utf8")
    cs = conn.cursor()
    cs.execute("select * from t_book;")

    # 游标从0开始，会自动下游，     游标归零:  rownumber=0
    res = cs.fetchone()  # 第一条
    res2 = cs.fetchone()  # 第二条
    res3 = cs.fetchmany(2)  # 第三和四两条
    res4 = cs.fetchall()  # 全部

    cs.rownumber = 1  # 游标归1
    res5 = cs.fetchmany(2)  # 取第二条和第三条

    print(res)
    print(res2)
    print(res3)
    # print(res4)
    print(res5)
except Exception as e:
    print("只需要打印",e)
finally:

    cs.close()
    conn.close()


